package MyIOTest;

import cn.hutool.core.util.ReUtil;
import cn.hutool.http.HttpUtil;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

public class test03 {
    public static void main(String[] args) throws IOException {
        String FamilyNameNet = "https://hanyu.baidu.com/shici/detail?pid=0b2f26d4c0ddb3ee693fdb1137ee1b0d&from=kg0";
        //男生名字网站
        String BoyNameNet = "https://www.mingziwang.cn/baobaoqiming/33951.html";
        //女生名字网站
        String GirlNameNet = "https://www.xingzuo.com/qiming/detail/235708.html";
        String FamilyName = HttpUtil.get(FamilyNameNet);
        String BoyName = HttpUtil.get(BoyNameNet);
        String GirlName = HttpUtil.get(GirlNameNet);
//        ArrayList<String> l1 = getData(FamilyName, "(.{4})(，|。)", 1);
//        ArrayList<String> l2 = getData(BoyName, "([\\u4E00-\\u9FA5]{2})(、|。)", 1);
//        ArrayList<String> l3 = getData(GirlName, "([\\u4E00-\\u9FA5]{2})(、|。)", 1);
        List<String> Family = ReUtil.findAll("([\\u4E00-\\u9FA5]{2})(、|。)", FamilyName, 1);
        List<String> Boy = ReUtil.findAll("([\\u4E00-\\u9FA5]{2})(、|。)", BoyName, 1);
        List<String> Girl = ReUtil.findAll("([\\u4E00-\\u9FA5]{2})(、|。)", GirlName, 1);
        ArrayList<String> FamilyList = new ArrayList<>();
        ArrayList<String> BoyList = new ArrayList<>();
        ArrayList<String> GirlList = new ArrayList<>();
        for (String s : Family) {
            for (int i = 0; i < s.length(); i++) {
                FamilyList.add(String.valueOf(s.charAt(i)));
            }
        }
        for (String s : Boy) {
            if(!BoyList.contains(s)){
                BoyList.add(s);
            }
        }
        for (String s : Girl) {
            if(!GirlList.contains(s)){
                GirlList.add(s);
            }
        }
//        System.out.println(FamilyList);
//        System.out.println(BoyList);
//        System.out.println(GirlList);
        ArrayList<String> name = toName(FamilyList, BoyList, GirlList, 30, 30);
        Collections.shuffle(name);
        BufferedWriter bw = new BufferedWriter(new FileWriter("csb.txt"));
        for (String s : name) {
            bw.write(s);
            bw.newLine();
        }
        bw.close();
        System.out.println(name);
    }
    public static ArrayList<String> toName(ArrayList<String> Family,ArrayList<String> Boy,ArrayList<String> Girl,int boyCount,int girlCount){
        ArrayList<String> list = new ArrayList<>();
        Random r = new Random();
        HashSet<String> Boys = new HashSet<>();
        while (true){
            if(boyCount == Boys.size()){
                break;
            }
            Collections.shuffle(Family);
            Collections.shuffle(Boy);
            Boys.add(Family.get(0) + Boy.get(0));
        }
        HashSet<String> Girls = new HashSet<>();
        while (true){
            if(Girls.size() == girlCount){
                break;
            }
            Collections.shuffle(Family);
            Collections.shuffle(Girl);
            Girls.add(Family.get(0) + Girl.get(0));
        }
        for (String boy : Boys) {
            list.add(boy + "-男-" + (r.nextInt(10) + 18));
        }
        for (String girl : Girls) {
            list.add(girl + "-女-" + (r.nextInt(10) + 18));
        }
        return list;
    }
}
